function validate() {
    $("#formEdit")
        .validate(
        {

            rules : {
                'nombre' : "required",
                'address.address' : "required",
                'countries.country' : "required",
                'regions.region' : "required",
                'cities.city' : "required",
                'hasListOfMembers' :  "required",
                'listOfMembersDate' :   {
                    required: true,
                    date: true
                },
                'inspectionZieherDate' :  {
                    required: true,
                    date: true
                },
                'inspectionZieherResults' :  {
                    required: true,
                    date: true
                },
                'sentToMoh': {
                    required: true,
                    date: true
                },
                'sivnotificationZieher' : "required",
                'enrollmentAuthorizationZieher': {
                    required: true,
                    date: true
                },
                'notification1stPatientZieher' : "required",
                'local' : "required",
                'signAllPages' : "required"

            },
            messages : {
                'nombre' : "Name is required",
                'address.address': "Address is required",
                'countries.country' : "Country is required",
                'regions.region' : "Region is required",
                'cities.city' : "City is required",
                'hasListOfMembers': "Has List Of Members is required",
                'listOfMembersDate' : { required : "List Of Members Date is required"  },
                'membersParticipating' : "Members Participating is required",
                'membersNotParticipating' : "List Of Members Not Participating is required",
                'gcpcompliance' : "GCP Compliance is requeried",
                'inspectionZieherDate' : { required :  "Inspection Zieher Date is required"  },
                'inspectionZieherResults' : { required :  "Inspection Zieher Results is required"  },
                'sentToMoh': { required : "Sent To MOH is required"  },
                'sivnotificationZieher' : "SIV Notification Zieher is required",
                'enrollmentAuthorizationZieher' : "Enrollment Authorization Zieher is required",
                'notification1stPatientZieher' : "Notification 1st Patient Zieher is required",
                'local' : "Local is required",
                'signAllPages' : "Sign All Pages is required"
            },
            errorElement : "label"

        })
}

function addRowCommitee(tableID) {

    var table = document.getElementById(tableID);

    var rowCount = table.rows.length;
    if(rowCount == 2 && table.rows[1].style.display == "none"){
        var row = table.rows[1];
        row.children[0].children[0].value = "";
        row.children[1].children[0].value = "";
        row.children[2].children[0].value = "";
        row.children[3].children[0].value = "";
        row.children[4].children[0].value = "";
        table.rows[1].style.display = "";
        return;
    }

    var counts = rowCount -1;

    var rowContact = $('#table_content tbody>tr:last').clone()[0];
    rowContact.children[0].children[0].value = '';
    rowContact.children[0].children[0].name = 'comiteEtica.contactPersons['+ counts +'].role.id';
    rowContact.children[1].children[0].value = '';
    rowContact.children[1].children[0].name = 'comiteEtica.contactPersons['+ counts +'].degree';
    rowContact.children[2].children[0].value = '';
    rowContact.children[2].children[0].name = 'comiteEtica.contactPersons['+ counts +'].email';
    rowContact.children[3].children[0].value = '';
    rowContact.children[3].children[0].name = 'comiteEtica.contactPersons['+ counts +'].fax';
    rowContact.children[4].children[0].value = '';
    rowContact.children[4].children[0].name = 'comiteEtica.contactPersons['+ counts +'].phone';
    rowContact.children[5].children[0].onclick = function(){deleteRow('table_content',this); return false;};

    $('#table_content > tbody:last').append(rowContact);
}

function deleteRow(tableID, button) {

    var table = document.getElementById(tableID);
    if(table.rows.length == 2){
        table.rows[1].style.display = "none";
    }else{
        table.deleteRow(button.parentNode.parentNode.rowIndex);
    }
}

function beforeSaveEthicsCommittee(tableID){
    var table = document.getElementById(tableID);
    var rowCount = table.rows.length;

    if(rowCount == 2 && table.rows[1].style.display == "none"){
        table.deleteRow(1);
    }
}

